package com.vcms.view.simulation.uicomponent.dialog;

import java.awt.Dialog;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */

import java.awt.event.ItemListener;
import java.awt.*;
import java.awt.event.ItemEvent;

@SuppressWarnings("serial")
public class FaultManager extends Dialog implements ItemListener {

	public static final char CHANGEGIVER = 'a';
	public static final char STORECOIN = 'b';
	public static final char DISPENSE = 'c';
	// public static final char RECEIVECOIN = 'd';
	public static final char NON = 'e';

	private char currentFault = NON;

	private Checkbox gc, dis, sc, non;

	public FaultManager(Frame fr) {
		super(fr, "Fault Manager", false);
		this.setLayout(new BorderLayout());
		Label lb = new Label("Fault may occure at:");
		this.add("North", lb);

		CheckboxGroup cbg = new CheckboxGroup();
		gc = new Checkbox("Give Changes", cbg, false); // initial state: off
														// (false)
		gc.addItemListener(this);
		dis = new Checkbox("Dispense", cbg, false); // initial state: off
		dis.addItemListener(this);
		sc = new Checkbox("Store Coin", cbg, false); // initial state: off
		sc.addItemListener(this);

		non = new Checkbox("Non", cbg, true); // initial state: on
		non.addItemListener(this);

		Panel pp = new Panel();
		pp.setLayout(new GridLayout(0, 1));
		pp.add(gc);
		pp.add(dis);
		pp.add(sc);
		pp.add(non);

		this.add("Center", pp);
		this.pack();
	}

	public void display() {
		this.setVisible(true);
	}

	public char getCurrentFault() {
		return currentFault;
	}

	public void itemStateChanged(ItemEvent e) {
		Checkbox cb;
		cb = (Checkbox) e.getSource();
		if (cb == gc) {
			currentFault = CHANGEGIVER;
			return;
		}
		if (cb == dis) {
			currentFault = DISPENSE;
			return;
		}

		if (cb == sc) {
			currentFault = STORECOIN;
			return;
		}

		if (cb == non) {
			currentFault = NON;
			return;
		}

		return;
	}

}